package com.job.demo.jobExample;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

@Component
@Async //多线程执行 异步
public class jobDemo {

    @Scheduled(cron = "* * * * * ?")
    public void jobDemo() {
        Random r = new Random();
        int i = r.nextInt(100);
//        if (i % 3 == 0) {
//            throw new RuntimeException("error");
//        }
        System.out.println(Thread.currentThread().getName() + " cron=* * * * * ? --- " + new Date());
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}